package com.immediatus.util;

import android.util.SparseArray;

public class Table<T>{
    protected final SparseArray<T> _Items;

    public Table(){
        this._Items = new SparseArray<T>();
    }

    public Table(final int capacity_){
        this._Items = new SparseArray<T>(capacity_);
    }

    public void put(final int id_, final T item_){
        final T existingItem = this._Items.get(id_);
        if (existingItem == null){
            this._Items.put(id_, item_);
        } else{
            throw new IllegalArgumentException("ID: '" + id_ + "' is already associated");
        }
    }

    public void remove(final int id_){
        this._Items.remove(id_);
    }

    public T get(final int id_){
        return this._Items.get(id_);
    }
}
